<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:mpeg7="urn:mpeg:mpeg7:schema:2001" xmlns:amp="mpeg7_amp" xmlns:voc="vocabularies" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="amp fn fo mpeg7 voc xs xsi">

<xsl:include href="top.xsl"></xsl:include>
<xsl:include href="down.xsl"></xsl:include>
<xsl:include href="utils.xsl"/>

<!-- Parametros del xsl -->
<xsl:param name="time"/>
<xsl:param name="base_url"/>
<xsl:param name="keys_search"/>
<xsl:param name="action"/>
<xsl:param name="id"/>
<xsl:param name="start"/>
<xsl:param name="order"/>

<xsl:variable name="base_img">img/mobile/</xsl:variable>


    <xsl:template match="/mpeg7:Mpeg7">
        <xsl:call-template name="top"/>
        <xsl:call-template name="topLogo"/>
        
        <xsl:apply-templates select="mpeg7:Description/mpeg7:MultimediaContent/mpeg7:Collection/mpeg7:ContentCollection/mpeg7:Content"/>

        
        
   
        <xsl:call-template name="down"/>
        
    </xsl:template>
    
    
    <xsl:template match="mpeg7:Content">
        <!--Identificador del contenido -->
        <xsl:variable name="id_content"><xsl:value-of select="@id"/></xsl:variable>
        <!--Tipo de contenido multimedia -->
        <xsl:variable name="type" select="@xsi:type"/>
        <xsl:variable name="video">Mpeg7:AudioVisualType</xsl:variable>
        <xsl:variable name="imagen">Mpeg7:ImageType</xsl:variable>

        
        <!--Se comprueba que el contenido solicitado esta disponible en el mpeg7 -->
        <xsl:if test="$id_content=$id">
        
            <!--Titulo del contenido -->                      
            <xsl:variable name="title">
                <xsl:call-template name="cleanTitle">
                    <xsl:with-param name="string" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:Title"/>
                </xsl:call-template>
            </xsl:variable>
            <!--Resumen (abstract del contenido)-->
            <xsl:variable name="resume" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:Abstract/mpeg7:FreeTextAnnotation"/>
            <!--Palabras clave -->
            <xsl:variable name="keywords" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:Abstract/mpeg7:KeywordAnnotation/mpeg7:Keyword"/>
            <!--Autor del contenido-->
            <xsl:variable name="author" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:Creator/mpeg7:Agent/voc:Name"/>
            <!-- Icono del repositorio -->
            <xsl:variable name="iconRep" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:Creator/mpeg7:Instrument/mpeg7:Tool/voc:Definition"/>
            
            <!-- Fecha de creaccion del contenido -->
            <xsl:variable name="date" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:CreationCoordinates/mpeg7:Date/mpeg7:TimePoint"/>
            <!--Categoria del contenido-->
            <xsl:variable name="category"><xsl:call-template name="exists"><xsl:with-param name="string" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Classification/mpeg7:Genre/voc:Name"/></xsl:call-template></xsl:variable>
            <!--Valoracion del contenido-->
            <xsl:variable name="rating"><xsl:call-template name="exists"><xsl:with-param name="string" select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Classification/mpeg7:MediaReview/mpeg7:Rating/mpeg7:RatingValue"/></xsl:call-template></xsl:variable>
                        
            <!-- Salida xhtml que compone los detalles del contenido -->
            <div class="vEntry padL3">       
		<table>
			<tbody>
				<tr>
                                    <td align="left" colspan="2"><div class="vdTitle"><xsl:value-of select="$title"></xsl:value-of></div></td>
				</tr>           
				<tr valign="top">
                                    <!--Se comprueba el tipo del contenido para mostrar su contenido -->
                                    <xsl:choose>
                                        <!--///////
                                            VIDEO
                                        ///////////-->
                                        <xsl:when test="$type=$video">    
                                            <!--Si es un video video/3gpp Mostramos ptra vista previa y enlace a reproducir -->
                                            <!--<xsl:variable name="play"><xsl:value-of select="mpeg7:AudioVisual/mpeg7:MediaInformation/mpeg7:MediaProfile[mpeg7:MediaInstance/mpeg7:LocationDescription='video/3gpp']/mpeg7:MediaInstance/mpeg7:InstanceIdentifier"/></xsl:variable>-->
                                                <xsl:variable name="play"><xsl:value-of select="mpeg7:AudioVisual/mpeg7:MediaInformation/mpeg7:MediaProfile[2]/mpeg7:MediaInstance/mpeg7:InstanceIdentifier"/></xsl:variable>
                                                <!--Imagen Vista previa -->
                                                <td class="tdThumb"><img alt="video" class="snapshot"><xsl:attribute name="src"><xsl:value-of select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:TitleMedia/mpeg7:TitleImage/mpeg7:MediaUri"/></xsl:attribute></img></td>       
                                                <td align="left">
                                                    <div class="subFooter"/>
                                                    <div class="line">
                                                        <xsl:call-template name="getIcons"><xsl:with-param name="tipo" select="$type"/></xsl:call-template>
                                                        <img><xsl:attribute name="src"><xsl:value-of select="$base_img"/><xsl:value-of select="$iconRep"/></xsl:attribute></img> 
                                                    </div>
                                                    <div class="line"><a><xsl:attribute name="href"><xsl:value-of select="$play"/></xsl:attribute>Reproducir</a></div>
                                                    <div></div>
                                                </td>     
                                              
                                        </xsl:when>
                                        
                                        <!--////////////
                                            IMAGEN
                                         /////////////-->
                                        <xsl:when test="$type=$imagen">
                                             
                                            <!--Enlaces a los otros tamaños (instancias de la fotografia)-->
                                            <!--Mediana-->
                                            <xsl:variable name="url_img_m"><xsl:value-of select="mpeg7:AudioVisual/mpeg7:MediaInformation/mpeg7:MediaProfile[mpeg7:MediaInstance/mpeg7:LocationDescription='img/medium']/mpeg7:MediaInstance/mpeg7:InstanceIdentifier"/></xsl:variable>
                                            <!--Grande-->
                                            <xsl:variable name="url_img_g"><xsl:value-of select="mpeg7:AudioVisual/mpeg7:MediaInformation/mpeg7:MediaProfile[mpeg7:MediaInstance/mpeg7:LocationDescription='img/big']/mpeg7:MediaInstance/mpeg7:InstanceIdentifier"/></xsl:variable>
                                            
                                                <!--Imagen Vista previa -->
                                                <td class="tdThumb"><img alt="video" class="snapshot"><xsl:attribute name="src"><xsl:value-of select="mpeg7:AudioVisual/mpeg7:CreationInformation/mpeg7:Creation/mpeg7:TitleMedia/mpeg7:TitleImage/mpeg7:MediaUri"/></xsl:attribute></img></td>       
                                                <td align="left">
                                                    <div class="line">
                                                        <xsl:call-template name="getIcons"><xsl:with-param name="tipo" select="$type"/></xsl:call-template>
                                                        <img><xsl:attribute name="src"><xsl:value-of select="$base_img"/><xsl:value-of select="$iconRep"/></xsl:attribute></img> 
                                                    </div>
                                                    <div class="subFooter">Tamaños:</div>
                                                    <div><a><xsl:attribute name="href"><xsl:value-of select="$url_img_m"/></xsl:attribute>Mediana </a></div>
                                                    <div><a><xsl:attribute name="href"><xsl:value-of select="$url_img_g"/></xsl:attribute>Grande </a></div>
                                                </td>  
                                           
                                        
                                        </xsl:when>
                                        
                                        <xsl:otherwise>
                                            El contenido no se puede visualizar
                                        </xsl:otherwise>
                                    </xsl:choose>
					
                                       
				</tr>      
				<tr>       
					<td align="center"></td>
				</tr>       
			</tbody>
		</table>
            </div>
            
            <!-- Autor -->
            <div class="vEntry padL3">   
		<div><b>Autor:</b>   
		<div><xsl:call-template name="normalizeXHTML"><xsl:with-param name="string" select="$author"/></xsl:call-template></div>
                </div>
            </div>
            
            <!-- Descripcion del contenido -->
            <div class="vEntry padL3">   
		<div><b>Descripcion:</b></div>   
		<div><xsl:call-template name="normalizeXHTML"><xsl:with-param name="string" select="$resume"/></xsl:call-template></div>
            </div>
            
            <!-- Palabras clave -->
            <div class="vEntry padL3">   
                <div><b>Keywords:</b></div>  
                <xsl:choose>
                    <xsl:when test="$keywords =''">
                        <div>No se han definido</div>   
                    </xsl:when>
                    <xsl:otherwise>
                        <div class="texto"><xsl:value-of select="$keywords"/></div>   
                    </xsl:otherwise>
                </xsl:choose>
		 
		
            </div>
            
            <div class="vEntry padL3">   
                <div><b>Fecha de creacción: </b><xsl:value-of select="$date"/></div>
                <div><b>Categoria: </b><xsl:value-of select="$category"/></div>
                <div><b>Valoración: </b><xsl:value-of select="$rating"/> sobre 5</div> 
                
            </div>
        
            <!--Volver atras -->
            <xsl:call-template name="back"/>
            
            
            
            
            
        </xsl:if>
    </xsl:template>
    
      <!--///////////////////////////
            Obtiene los iconos de tipo de contenido y repositorio
    ///////////////////////////////////////////////////-->
    <xsl:template name="getIcons">
            <xsl:param name="tipo"/>

            <xsl:choose>
                <xsl:when test="$tipo='Mpeg7:ImageType'">
                    <xsl:variable name="icon_type"><xsl:value-of select="$base_img"/>imagen.gif</xsl:variable>
                    <xsl:variable name="type">imagen</xsl:variable>
                    <img class="iconL"><xsl:attribute name="src"><xsl:value-of select="$icon_type"/></xsl:attribute></img>   
                </xsl:when>
                <xsl:when test="$tipo='Mpeg7:AudioVisualType'">
                   <xsl:variable name="icon_type"><xsl:value-of select="$base_img"/>video.gif</xsl:variable>
                   <xsl:variable name="type">video</xsl:variable>
                   <img class="iconL"><xsl:attribute name="src"><xsl:value-of select="$icon_type"/></xsl:attribute></img>   
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="icon_type"><xsl:value-of select="$base_img"/>video.gif</xsl:variable>
                    <img class="iconL"><xsl:attribute name="src"><xsl:value-of select="$icon_type"/></xsl:attribute></img>   
                </xsl:otherwise>
            </xsl:choose>
            
                     
    </xsl:template>
    
    
    <!--// Enlace para volver atras -->
    <xsl:template name="back">
         <div class="menu_pie">    
            <a id="volver"><xsl:attribute name="href"><xsl:value-of select="$base_url"/><xsl:value-of select="$keys_search"/>&amp;start=<xsl:value-of select="$start"/><xsl:call-template name="_order"/></xsl:attribute>Volver</a>
        </div>
    </xsl:template>
    
            
    <!--/////////////////////////////////////////////////////
    Se obtiene la url para la paginacion si hay filtro de ordenacion
    //////////////////////////////////////////////-->
    <xsl:template name="_order">
        <!--Posible inclusion de filtro de ordenacion-->
        <xsl:choose>
            <xsl:when test="$order!=''">&amp;order=rating</xsl:when>
            <xsl:otherwise></xsl:otherwise>
        </xsl:choose>    
    </xsl:template>
    
</xsl:stylesheet>
